package cq.zhcqk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import cq.zhcqk.R;
import cq.zhcqk.util.StringUtil;

/**
 * Created by zhangle on 2017/12/10.
 */
public class DyxxDetailAdapter extends BaseAdapter{
    List<Map<String, Object>> list;
    Context context;
    public DyxxDetailAdapter(Context context, List<Map<String, Object>> list){
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list ==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final viewHolder holder;
        if(convertView == null){
            holder = new viewHolder();
            convertView = View.inflate(context, R.layout.item_dyxx_detail,null);
            holder.dyd_zb = (TextView) convertView.findViewById(R.id.dyd_zb);
            holder.dyd_name = (TextView) convertView.findViewById(R.id.dyd_name);
            holder.dyd_time = (TextView) convertView.findViewById(R.id.dyd_time);
            convertView.setTag(holder);
        }else{
            holder = (viewHolder) convertView.getTag();
        }

        Map<String, Object> info = list.get(position);
        holder.dyd_zb.setText(info.get("deptname")+"");
        holder.dyd_name.setText(info.get("username")+"");
        holder.dyd_time.setText(StringUtil.stringToInt(info.get("studytime")+"")+"分钟");
        return convertView;
    }

    private class viewHolder{
        private TextView dyd_zb;
        private TextView dyd_name;
        private TextView dyd_time;
    }
}
